package branch_and_price;

import java.util.ArrayList;

// 存储算例数据
public class Data {
    public static double BigNum = 1000000;
    // 访问点的数量
    private int n;
    // 访问点的坐标（vertex[i][0]表示x点的坐标，vertex[i][1]表示y点的坐标）
    private double[][] vertex;
    // 距离矩阵
    private double[][] c;
    // 用来记录运算中的数据？
    private Configure conf;

    public Data(int n1, double[][] vertex1){
        this.n = n1;
        this.vertex = new double[n][2];
        for (int i = 0; i < n; i++) {
            this.vertex[i][0] = vertex1[i][0];
            this.vertex[i][1] = vertex1[i][0];
        }
        this.makeDistance();
        conf = new Configure();
    }

    // 根据坐标矩阵，计算距离矩阵
    public void makeDistance() {
        c = new double[n][n];
        for (int i = 0; i < n; i++) {
            c[i][i] = BigNum;
            for (int j = 0; j < i; j++) {
                this.c[i][j] = Math.sqrt(Math.pow(vertex[i][0] - vertex[j][0], 2) + Math.pow(vertex[i][1] - vertex[j][1], 2));
                this.c[j][i] = this.c[i][j];
            }
        }
    }

    // 将数据打印出来
    public void show(){
        System.out.println("--------------------- city information ---------------------");
        for (int i = 0; i < n; i++) {
            System.out.println("id: "+i+", x: "+vertex[i][0]+", y: "+vertex[i][1]);
        }
        System.out.println("------------------------------------------------------------");
    }

    // 计算路径成本
    public double cal_cost(ArrayList<Integer> r){
        double cost = 0;
        for (int i = 0; i < r.size()-1; i++) {
            cost+=c[r.get(i)][r.get(i+1)];
        }
        return cost;
    }

    public int getN() {
        return n;
    }

    public Configure getConf() {
        return conf;
    }

    public double[][] getC() {
        return c;
    }
}